<?php

class Application_Form_ProfileEdit extends Zend_Form {

    public function init() {
        $this->setAction('/admin/account/edit')
                ->setMethod('post')
                ->setAttrib('id', 'profileEditForm')
                ->addElementPrefixPath('ZendBlog_Validate', 'ZendBlog/validate/', 'validate')
                ->setDecorators(ZendBlog_Decorator_Decorator::Form());

        /* Username */
        $this->addElement('text', 'username', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => 'Username',
            'attribs' => array(
                'disabled' => true,
                'readonly' =>true
            )
        ));

        /* name */
        $this->addElement('text', 'name', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => 'Name',
            'required' => true
        ));

        /* Email */
        $this->addElement('text', 'email', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => 'Email',
            'validators' => array('emailAddress', array(
                    'db_NoRecordExists', false,
                    array(
                        'table' => 'users',
                        'field' => 'email',
                        'exclude' => array(
                            'field' => 'id',
                            'value' => Zend_Auth::getInstance()->getIdentity()->id
                        )
                ))
            ),
            'filter' => array('StringTrim', 'StringToLower'),
            'required' => true
        ));

        /* Edit button */
        $this->addElement('submit', 'Edit', array(
            'decorators' => ZendBlog_Decorator_Decorator::Submit()
        ));

        /* Hidden Id */
        $this->addElement('hidden', 'id', array(
            'validators' => array('Digits'),
            'required' => true
        ));
    }

}

